/* global chrome */
import request from './request';

// 监听来自content script的消息
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.type === 'REPORT_RESUME') {
    // 处理报备简历请求
    handleReportResume(message.data)
      .then(response => {
        sendResponse({ success: true, data: response });
      })
      .catch(error => {
        sendResponse({ success: false, error: error.message });
      });
    
    // 返回true表示将异步发送响应
    return true;
  }
});

// 处理报备简历请求
async function handleReportResume(data) {
  try {
    console.log('报备简历请求数据:', data);
    const response = await request.post('/oa_report/submitCandidate/increaseResumeResource', data);
    return response.data;
  } catch (error) {
    console.error('报备简历请求失败:', error);
    throw error;
  }
}